// 检测关键节点
<template>
    <f7-page class="hntsh">
        <f7-navbar>
            <f7-nav-left>
                <f7-link back icon-material="chevron_left" force></f7-link>
            </f7-nav-left>
            <f7-nav-title>检测关键节点</f7-nav-title>
            <f7-nav-right> </f7-nav-right>
        </f7-navbar>
        <div class="wbList">
            <v-picture-item
                v-for="(item, index) in picList"
                :key="index"
                :ref="`keyNode${index + 1}`"
                :props="{ name: 'customName' }"
                :index="item.detailIndex"
                typeCode="EQM_CHECK_ITEM"
                :address="address"
                isDefaultFile
                :disabled="!isWrite"
                :item="item"
                :dataKey="caseId"
                :bizType="item.bizType"
                listName="keyNode"
            />
        </div>
        <f7-toolbar position="bottom" no-shadow class="fff" v-if="isWrite">
            <f7-button fill class="submit-btn" @click="sure()">保存</f7-button>
        </f7-toolbar>
    </f7-page>
</template>

<script>
import controller from '@/libs/framework/controller'
export default class instance extends controller {
    mixin() {
        return {
            props: {
                caseId: {
                    type: String,
                },
                isWrite: {
                    type: Boolean,
                },
                address: {
                    type: String,
                },
            },
            data() {
                return {
                    picList: [],
                    attachCraneType: '',
                }
            },
            mounted() {
                this.getType()
            },
            methods: {
                getType() {
                    this.$f7.request.post(
                        `/app/equipment/eqmCheck/queryVitalsDetect`,
                        {
                            caseId: this.caseId,
                        },
                        (r) => {
                            r = JSON.parse(r)
                            if (r && r.success) {
                                this.attachCraneType = r.parameters.craneType
                                this.getFileList()
                            } else {
                                this.$toast(r.message || '网络错误，请稍后重试')
                            }
                        }
                    )
                },
                getFileList() {
                    this.$f7.request.post(
                        '/admin/attachmentFormDetail/listUpload',
                        {
                            typeCode: 'EQM_CHECK_ITEM',
                            dataKey: this.caseId,
                            attachCraneType: this.attachCraneType,
                        },
                        (r) => {
                            r = JSON.parse(r)
                            if (r?.success && r.parameters.fileList) {
                                this.picList = r.parameters.fileList
                            } else {
                                this.$framework.$f7.dialog.toast('获取文件失败')
                            }
                        }
                    )
                },
                //提交
                sure() {
                    let count = 0
                    this.picList.forEach((element, index) => {
                        if (
                            element.isMustUpload &&
                            this.$refs[
                                `keyNode${index + 1}`
                            ][0].getUploadedCount() < 1 &&
                            !element.isNil
                        ) {
                            count++
                        }
                    })
                    if (count > 0) {
                        this.$toast('请上传必传附件')
                        return
                    }
                    this.$f7.dialog.alert('保存成功', () => {
                        this.$f7.views.current.router.back({force:true})
                    })
                },
            },
        }
    }
}
</script>

<style lang="less" scoped>
@import url('../../../../assets/css/qualityCreate.less');
@deep: ~'>>>';

@{deep} .page-content {
    padding-top: 50px;
    background: #fff;
}

.hntsh {
    .content-list {
        padding: 0 0 50px;
    }

    @{deep} .pic_upload {
        padding-top: 10px;
    }

    @{deep} .toolbar,
    @{deep}.navbar {
        position: fixed;
    }
    .wbList {
        @{deep}.content-box {
            padding: 10px 15px;
            display: flex;
            align-items: flex-start;
        }
    }
}
</style>
